import 'package:flutter/material.dart';
import 'package:xindong/common/xindong_sezhi.dart';

class XinDongCommonButton extends StatelessWidget {
  final String title;
  final EdgeInsets? padding;
  final TextStyle? textStyle;
  final double? width;
  final double? height;
  final Function()? onTap;

  const XinDongCommonButton(
    this.title, {
    Key? key,
    this.padding,
    this.textStyle,
    this.width,
    this.height,
    required this.onTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    const ts = TextStyle(fontSize: 16, fontWeight: FontWeight.normal, height: 1.2, color: Colors.white);
    return GestureDetector(
      onTap: onTap,
      behavior: HitTestBehavior.opaque,
      child: Container(
        width: width,
        height: height,
        padding: padding ?? const EdgeInsets.only(left: 16, right: 16),
        alignment: Alignment.center,
        decoration: BoxDecoration(
          borderRadius: const BorderRadius.all(Radius.circular(50)),
          // 渐变色
          gradient: LinearGradient(
            begin: Alignment.centerLeft,
            end: Alignment.centerRight,
            colors: onTap != null ? [DZColors.mainColor, DZColors.hexStringColor("#EF7AB6")] : [DZColors.disabledColor, DZColors.disabledColor],
          ),
        ),
        child: Text(title, style: textStyle ?? ts),
      ),
    );
  }
}

// 带边框Button
class XinDongCommonBorderButton extends StatelessWidget {
  final String title;
  final TextStyle? textStyle;
  final EdgeInsets? padding;
  final Function()? onTap;
  final Color backgroundColor;

  const XinDongCommonBorderButton(this.title, {Key? key, this.textStyle, this.padding, this.backgroundColor = Colors.white, required this.onTap})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    const ts = TextStyle(color: DZColors.mainColor, fontSize: 16, fontWeight: FontWeight.normal, height: 1.2);
    return GestureDetector(
      onTap: onTap,
      child: Container(
        decoration: BoxDecoration(
          color: backgroundColor,
          borderRadius: const BorderRadius.all(Radius.circular(50)),
          border: Border.all(color: DZColors.mainColor, width: 1),
        ),
        alignment: Alignment.center,
        padding: padding ?? const EdgeInsets.only(left: 16, right: 16),
        child: Text(title, style: textStyle ?? ts),
      ),
    );
  }
}

class XinDongInputButton extends StatelessWidget {
  final String hintText;
  final String hintText2;
  final String? data;
  final bool isCity;
  final Function() onTap;

  const XinDongInputButton({Key? key, required this.hintText, this.data, required this.onTap, this.isCity = false, this.hintText2 = ""})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Row(
        children: [
          Expanded(
            child: Text(
              (data == null || data!.isEmpty) ? hintText : data!,
              style: TextStyle(fontSize: 16, color: (data == null || data!.isEmpty) ? DZColors.placeholderColor : DZColors.titleColor, height: 1.2),
              textAlign: TextAlign.start,
            ),
          ),
          if (isCity)
            Text(
              hintText2,
              style: const TextStyle(color: DZColors.mainBlueColor, fontSize: 15),
            ),
          const SizedBox(width: 16)
        ],
      ),
    );
  }
}
